﻿package com.guavestudios.fcon.plugins {
	import com.guavestudios.fcon.api.IControlableConsole;
	
	/**
	* ...
	* @author Default
	*/
	public class ConstantsPlugin implements IConstantsProvider,IConsolePlugin {
		
		private var constantMap:Object;
		private var constantArray:Array;
		
		private var console:IControlableConsole;
		
		public function ConstantsPlugin() {
			constantMap = new Object();
			constantArray = new Array();
		}
		
		
		//{ Constant map functions
		public function getConstant(id:String):Object
		{
			return constantMap[id];
		}
		public function setConstant(id:String,obj:Object):void
		{
			if (obj == null)
			{
				removeConstant(id);
				return;
			}
			if (!hasConstant(id))
			{
				constantArray.push(id);
			}
			constantMap[id] = obj;
			
		}
		public function removeConstant(id:String):void
		{
			if (hasConstant(id))
			{
				constantMap[id] = undefined;
				constantArray.splice(constantArray.indexOf(id), 1);
			}
			
		}
		public function hasConstant(id:String):Boolean
		{
			return constantMap[id] != undefined;
		}
		public function getConstantIds():Array
		{
			return constantArray;
		}
		//}
		
		/* INTERFACE com.guavestudios.fcon.plugins.IConsolePlugin */
		public function get State():int{
			return 0;
		}
		
		public function get Name():String{
			return "ConstantsPlugin";
		}
		
		public function get Version():String{
			return "1.0";
		}
		
		public function initPlugin(c:IControlableConsole):void{
			console = c;
		}
		
		public function unloadPlugin():void{
			console = null;
			constantArray = null;
			constantMap = null;
		}
		
	}
	
}